import sys
import enemy

class map_proccessor:
    def __init__(self, screen_size, players, filename = "1.map", path = ""):

        self.players = players
        
        self.screen_size = screen_size
        self.obj_info_list = []

        for line in open(path + filename):
            line_item = line.split(' ')
            self.obj_info_list.append(line_item[0:-1])
#            print line_item[0:-1]
        self.obj_info_list.sort(lambda x, y: cmp(x[0],y[0]))

        temp_line = self.obj_info_list.pop(0)
        
        self.boss_num = temp_line[1]

    def get_boss_num(self):
        return int(self.boss_num)

    def get_top_info(self, current_time):
        if (len(self.obj_info_list) == 0):
            return -1       #if the list is empty return EOF
        else:
            if (current_time >= int(self.obj_info_list[0][0])):
                return self.obj_info_list.pop(0)    #if the first item of the list is OK, return it
            else:
                return []                           #if there is no item fullfill the request, return an empty list

    def get_available_obj(self, current_time):
        temp_top_info = self.get_top_info(current_time)
        if (temp_top_info == -1):
            return False                               #if the first item of the list is OK, return it
        
        if (temp_top_info != []):

            location = int(temp_top_info[1])
            main_type = int(temp_top_info[2])
            sub_type = int(temp_top_info[3])
            motion_type = int(temp_top_info[4])

            if (main_type == 1): # enemy
                enemy.enemy_obj(self.screen_size, (location, 0), sub_type, motion_type, self.players)
                return True
                pass
            elif (main_type == 2): # items
                return True
                pass
            elif (main_type == 3): # blocks
                return True
                pass
            else:
                pass
                return False
                
            return 
        else:
            return False                             #if there is no item fullfill the request, return None
